import Vue from 'vue'

import Vuex from 'vuex'
Vue.use(Vuex)

export  default new Vuex.Store({
    state:{
        count:0
    },
    mutations:{
        storePlus(state){
            state.count++
        },
        storeReduce(state){
            state.count--
        },
        storePlusN(state,n){
            state.count+=n
        },
        storeReduceN(state,n){
            state.count-=n
        },

    },
    actions:{
        storePlusNAsync(context,stepTime){
            setTimeout(()=>{
                context.commit('storePlusN',stepTime.step);
            },stepTime.time)
        },
        storePlusNAsync1(context,stepTime){
            setTimeout(()=>{
                context.commit('storePlusN',stepTime.step);
            },stepTime.time)
        }
    },
    getters:{
        showNum : state =>{
            return '最新的count值为：'+state.count;
        }
    }
})